package com.example.message.quartz;

import org.quartz.CronScheduleBuilder;
import org.quartz.JobBuilder;
import org.quartz.JobDetail;
import org.quartz.SimpleScheduleBuilder;
import org.quartz.Trigger;
import org.quartz.TriggerBuilder;
import org.springframework.boot.SpringBootConfiguration;
import org.springframework.context.annotation.Bean;

@SpringBootConfiguration
public class JobQuartzConfig {

    // JobDetail
    @Bean
    public JobDetail weatherDataSyncJobDetail() {
        return JobBuilder.newJob(TestQuartzSyncJob.class).withIdentity("TestQuartzSyncJob")
                .storeDurably().build();
    }
    // Trigger
    @Bean
    public Trigger weatherDataSyncTrigger() {
        // 方式一：更新频率  5秒
        /*SimpleScheduleBuilder builder = SimpleScheduleBuilder.simpleSchedule().withIntervalInSeconds(5).repeatForever();
        return TriggerBuilder.newTrigger().forJob(weatherDataSyncJobDetail())
                .withIdentity("weatherDataSyncTrigger").withSchedule(builder).build();*/
        // 方式二：使用CRON表达式
        return TriggerBuilder.newTrigger().forJob(weatherDataSyncJobDetail())
                .withIdentity("weatherDataSyncTrigger").withSchedule(CronScheduleBuilder.cronSchedule("0/3 * * * * ?")).build();
    }

}
